﻿using System.IO;

namespace Microsoft.Azure.E2E.Common.Net
{    
    /// <summary>
    /// A part of a <see cref="MultipartMessage"/> that contains a string
    /// </summary>
    public class StringPart : MessagePart
    {
        private readonly string _value;
        private readonly string _name;

        /// <summary>
        /// Creates a new <see cref="StringPart"/>
        /// </summary>
        /// <param name="name">The name of the message part</param>
        /// <param name="value">The value the message part should contain</param>
        public StringPart(string name, string value)
        {
            _name = name;
            _value = value;
        }
        
        /// <summary>
        /// Gets the name of the part
        /// </summary>
        public override string Name
        {
            get { return _name; }
        }

        /// <summary>
        /// Gets the content disposition header value for the part
        /// </summary>
        public override string ContentDisposition
        {
            get { return "form-data"; }
        }

        /// <summary>
        /// Gets a stream representing the value contained in the part
        /// </summary>
        /// <returns>A stream representing the value contained in the part</returns>
        protected override Stream GetDataStream()
        {
            return StreamFromString(_value);
        }
    }
}